/**
 * Created by IntelliJ IDEA
 *
 * @author zhengjie
 * @Date:2022/1/8 11:47
 * @Version 1.0
 */
package com.zj.ssm.service.impl;

import com.zj.ssm.mapper.DepartmentMapper;
import com.zj.ssm.pojo.domain.Department;
import com.zj.ssm.pojo.domain.DepartmentDetails;
import com.zj.ssm.pojo.domain.vo.DepartmentVO;
import com.zj.ssm.result.AjaxResult;
import com.zj.ssm.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepartmentServiceImpl implements DepartmentService {

    @Autowired
    public DepartmentMapper departmentMapper;

    @Override
    public AjaxResult list() {
        List<Department> departments = departmentMapper.listAll();
        return AjaxResult.success(departments);
    }

    @Override
    public AjaxResult liststate() {
        List<Department> ds = departmentMapper.liststate();
        return AjaxResult.success(ds);
    }

    @Override
    public AjaxResult listDetails(Integer id) {
        DepartmentDetails details = departmentMapper.listDetails(id);
        return AjaxResult.success(details);
    }

    @Override
    public AjaxResult updateDetails(DepartmentDetails departmentDetails) {
      int i = departmentMapper.updateDetails(departmentDetails);
      if (i>0){
          return AjaxResult.success();
      }
        return AjaxResult.fail();
    }



    @Override
    public AjaxResult getdep(Integer id) {
        DepartmentVO d = departmentMapper.getdep(id);
        return AjaxResult.success(d);
    }

    @Override
    public AjaxResult updatedep(DepartmentVO departmentVO) {
        int i =departmentMapper.updatedep(departmentVO);
        if (i>0){
            return AjaxResult.success();
        }
        return AjaxResult.fail();
    }

    @Override
    public AjaxResult adddep(DepartmentVO departmentVO) {
        DepartmentVO departmentVO1 = departmentMapper.getDepName(departmentVO);
        if (departmentVO1==null){
            int i = departmentMapper.adddep(departmentVO);
            if (i>0){
                return AjaxResult.success();
            }
        }
        return AjaxResult.fail();
    }

    @Override
    public AjaxResult querydep() {

    List<Department> departments = departmentMapper.querydep();
        return AjaxResult.success(departments);
    }

    @Override
    public AjaxResult updateDepart(Integer id) {
        int i = departmentMapper.updateDepart(id);
        if (i>0){
            return AjaxResult.success();
        }
        return AjaxResult.fail();
    }

    @Override
    public AjaxResult departUpdate(Integer id) {
        int i = departmentMapper.departUpdate(id);
        if (i>0){
            return AjaxResult.success();
        }
        return AjaxResult.fail();
    }




}
